import time
import os
import adb_utils


def main():
    timestamp = time.strftime("%Y-%m-%d_%H%M%S", time.localtime())
    devices = adb_utils.command_devices()
    for device in devices:
        name = device.replace(".", "-").replace(":", "_")
        folder = "debug_{}_{}".format(timestamp, name)
        container_hilog = "{}/container_hilog".format(folder)
        container_faultlog = "{}/container_faultlog".format(folder)
        os.makedirs(container_hilog)
        os.makedirs(container_faultlog)

        adb_utils.command_pull(device, "/data/log/hilogs/", folder)
        adb_utils.command_pull(device, "/data/tombstones/", folder)
        adb_utils.command_pull(device, "/data/log/dropbox/", folder)
        adb_utils.command_pull(device, "/sys/kernel/debug/binder", folder)
        adb_utils.command_pull(device, "/data/log/faultlog/", folder)
        adb_utils.command_pull(device, "/data/log/bt/", folder)
        adb_utils.command_pull(
            device, "/data/ohos_data/log/hilog", container_hilog)
        adb_utils.command_pull(
            device, "/data/ohos_data/log/faultlog", container_faultlog)

    adb_utils.dump_timestamp("get log finished")


if __name__ == "__main__":
    main()
